package com.neu.dao.impl;

import com.neu.dao.BaseDao;
import com.neu.dao.ClientDao;
import java.util.List;
import java.util.Map;

public class ClientDaoImpl extends BaseDao implements ClientDao {

    /**
     * 登录方法
     * @param name 用户名
     * @param pwd  用户密码
     * @return
     */
    @Override
    public Map<String, Object> login(String name, String pwd) {
        Map<String,Object> map = null;
        String sql = "select * from t_client where client_name = ? and client_pwd = md5(?) and client_status = 1";
        List<Map<String, Object>> list = excuteQuery(sql,name,pwd);
        if(list.size() > 0){
            map = list.get(0);
        }
        return map;
    }

    /**
     * 注册方法
     * @param name 用户名
     * @param pwd  用户密码
     * @param sex  性别 0女,男1
     * @param birthday 生日
     * @param client_tel 联系电话
     * @return
     */
    @Override
    public int register(String name, String sex, String birthday, String pwd,String client_tel) {
        int row = 0;
        String sql = "insert into t_client(client_name,sex,client_birthday,client_pwd,client_tel)" +
                " VALUES(?,?,?,MD5(?),?)";
        row = executeUpdate(sql,name,sex,birthday,pwd,client_tel);
        return row;
    }

    /**
     * 查询当前客户信息
     * @param client_no
     * @return
     */
    @Override
    public Map<String, Object> searchClient(String client_no) {
        Map<String,Object> map = null;
        String sql = "select * from t_client where client_no = ? and client_status = 1";
        List<Map<String,Object>> list = excuteQuery(sql,client_no);
        if(list.size() > 0){
            map = list.get(0);
        }
        return map;
    }

    /**
     * 修改当前用户信息
     * @param client_no 当前用户编号
     * @param client_name 用户姓名
     * @param birthday    出生年月
     * @return
     */
    @Override
    public int updateClinetMsg(String client_no, String client_name, String birthday) {
        int row = 0;
        String sql = "update t_client set client_name = ?,birthday = ? where client_no = ?";
        row = executeUpdate(sql,client_name,birthday,client_no);
        return row;
    }

    /**
     * 修改当前用户密码
     * @param client_no    当前用户编号
     * @param clientOldPwd 旧密码
     * @param clientNewPwd 新密码
     * @return
     */
    @Override
    public int updateClientPwd(String client_no, String clientOldPwd, String clientNewPwd) {
        int row = 0;
        String sql = "update t_client set client_pwd = md5(?) where client_pwd = md5(?) and client_no = ?";
        row = executeUpdate(sql,clientNewPwd,clientOldPwd,client_no);
        return row;
    }
}
